/****************************************
* James Gomez                           *
* Project 3: Target Practice P3         *
* Comp 465                              *
* Professor Barnes                      *
* 12/7/2012                             *
*****************************************/

#ifndef _MISSILE_
#define _MISSILE_

#include "GomezJamesP3_OpenGL.h"
#include "GomezJamesP3_Torpedo.cpp"

//extern ::PlayerShip * warbird;

class Missile: public Torpedo{

private:
	GLfloat degreeOfRotation;
	CollidableObject * target;

public:
	Missile(CollidableObject * target, const int lifespan, const GLfloat startM[16]);
	~Missile(){}	

	void seekTarget();
};


Missile::Missile(CollidableObject * target, const int lifespan, const GLfloat startM[16]):
	Torpedo(red, lifespan, startM){
	
	this->target = target;
	degreeOfRotation = 10.0;	
}

//Override
void Missile::seekTarget(){

	Vector3D targetV = target->getLocationV();
	targetV.subtract(this->getLocationV());		
		
	Vector3D axis = getAtV().crossProduct(targetV.getNormalizedV());
	axis.normalize();	
	
	//orient torpedo towards target
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadMatrixf(OM);
	glRotatef(degreeOfRotation, axis.getX(), axis.getY(), axis.getZ());
	glGetFloatv(GL_MODELVIEW_MATRIX, OM);
	glPopMatrix();

}

#endif